package org.lottery.entity;

import java.util.Set;

import org.lottery.activity.R;
import org.lottery.util.CalcUtil;
import org.lottery.util.ImageUtil;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;

public class ImageAdapter extends BaseAdapter {

    private Context mContext;

    public int length = 24;
    private Set<Integer> nBingo;
    private UserSettings us;

    public Integer[] fullImages = {
            R.drawable.image1,
            R.drawable.image2,
            R.drawable.bingo,
            R.drawable.chuc_ban_may_man_lan_sau
    };

    // Constructor
    public ImageAdapter(Context c, UserSettings us) {

        this.us = us;
        nBingo = CalcUtil.findBingo(0, length - 1, us.getQuantity());
        for (Integer i : nBingo) {
            System.out.println("Bingo number is : " + (i + 1));
        }
        mContext = c;
    }

    @Override
    public int getCount() {

        return length;
    }

    @Override
    public Object getItem(int position) {

        return Integer.valueOf(position);
    }

    @Override
    public long getItemId(int position) {

        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        CardGraphicView cardView = new CardGraphicView(mContext);

        Drawable openCard = ImageUtil.initRewardPicture(us.getOpenPath(), us.getResources());
        if(openCard!=null){
        	cardView.setImageDrawable(openCard);	
        }else{
        	cardView.setImageResource(R.drawable.thumb2);
        }
        cardView.setScaleType(CardGraphicView.ScaleType.CENTER_CROP);
        cardView.setLayoutParams(new GridView.LayoutParams(160, 160));
        if (nBingo.contains(Integer.valueOf(position))) {
            cardView.setBingo(true);
        }
        return cardView;
    }

}
